#include "MainWindow.h"
#include "ui_MainWindow.h"

#include <QGridLayout>
#include <QPainter>
#include <QDebug>

#include "DisplayWidget.h"
#include "FaceDetector.h"
#include "Capturer.h"
#include "Mask.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    displayWidget(new DisplayWidget()),
    faceDetector(new FaceDetector())
{
    ui->setupUi(this);
    ui->centralWidget->setLayout(new QGridLayout());
    ui->centralWidget->layout()->setSpacing(0);
    ui->centralWidget->layout()->setMargin(0);
    ui->centralWidget->layout()->addWidget(displayWidget);

    connect(faceDetector, SIGNAL(detectedFaces(QVector<Face>)), displayWidget, SLOT(setFaces(QVector<Face>)));
}

MainWindow::~MainWindow()
{
    delete ui;
    delete displayWidget;
}

void MainWindow::on_actionCapture_Video_triggered()
{
    Capturer* capturer = Capturer::createCameraCapturer(0);
    connect(capturer, SIGNAL(capturedNewImage(QImage)), displayWidget, SLOT(newImage(QImage)));

    connect(capturer, SIGNAL(capturedNewImage(QImage)), faceDetector, SLOT(detectFaces(QImage)), Qt::DirectConnection);

    capturer->startCapture();
}

void MainWindow::newImage(QImage image)
{
    currentImage = image;
}
